package com.imooc.bo;

import com.imooc.enums.YesOrNo;
import com.imooc.pojo.UserAddress;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotEmpty;
import java.util.Date;

/**
 * <h1>收货地址bo</h1>
 *
 * @author : dzj
 * @create: 2022-02-20 16:29
 */
@Data
@ApiModel(value = "收货地址添加BO")
public class AddressBo {

    private String addressId;
    @NotEmpty
    private String userId;
    @NotEmpty
    @Length(max = 12)
    private String receiver;
    @NotEmpty
    @Length(min = 11,max = 11)
    private String mobile;
    @NotEmpty
    private String province;
    @NotEmpty
    private String city;
    @NotEmpty
    private String district;
    @NotEmpty
    private String detail;

    public UserAddress convert(boolean isDefault) {
        UserAddress ua = new UserAddress();
        if(this.addressId!=null) {
            ua.setId(this.addressId);
        }
        ua.setUserId(this.userId);
        ua.setReceiver(this.receiver);
        ua.setProvince(this.province);
        ua.setDistrict(this.district);
        ua.setCity(this.city);
        ua.setDetail(this.detail);
        ua.setMobile(this.mobile);
        Date now = new Date();
        ua.setCreatedTime(now);
        ua.setUpdatedTime(now);
        ua.setIsDefault(isDefault? YesOrNo.YES.getCode():YesOrNo.NO.getCode());
        return ua;
    }
    public UserAddress convert() {
        UserAddress ua = new UserAddress();
        if(this.addressId!=null) {
            ua.setId(this.addressId);
        }
        ua.setUserId(this.userId);
        ua.setReceiver(this.receiver);
        ua.setProvince(this.province);
        ua.setDistrict(this.district);
        ua.setCity(this.city);
        ua.setDetail(this.detail);
        ua.setMobile(this.mobile);
        Date now = new Date();
        ua.setCreatedTime(now);
        ua.setUpdatedTime(now);
        return ua;
    }
}
